
export default {
  state: {
    brandList: [],
    brandAllTemplate: []
  },
  mutations: {
    setBrandList (state, val) {
      state.brandList = val
    },
    setBrandAllTemplate (state, val) {
      state.brandAllTemplate = val
    }
  },
  actions: {
    async getBrandList ({dispatch, commit, state}) {
      if (state.brandList.length) return
      let res = await dispatch('fetch', {url: '/getBrandList'})
      if (res && res.success) return commit('addLandingPage/setBrandList', res.list)
      commit('addLandingPage/setBrandList', [])
    },
    async getAllTempLateByBrandId ({dispatch, commit, state}, brandId) {
      let res = await dispatch('fetch', {url: `/getAllTempLateByBrandId/${brandId}`})
      if (res && res.success) return commit('addLandingPage/setBrandAllTemplate', res.list)
      commit('addLandingPage/setBrandAllTemplate', [])
    },
    async getTemplateById ({dispatch}, templateId) {
      let res = await dispatch('fetch', {url: `/getTemplateById/${templateId}`})
      return res
    },
    async previewTemplate ({dispatch}, params) {
      let res = await dispatch('fetch', {url: '/previewTemplate', params})
      return res
    }
  }
}